<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<%@ include file="../root.jsp" %>
<style type="text/css">
#searchTable td
{
	text-align: left;
}
</style>
</head>
<body  class="easyui-layout" fit="true">
    <div data-options="region:'north',collapsed:true" title="查询" style="height:117px;">
	<form id="searchForm" style="text-align: center;">  
        <table id="searchTable" width="100%">  
            <tr> 
            <td>车站：
                    <select id="station-select" name="station" >
                        <option value="">&nbsp;</option>
                    </select>
            </td>    
            <td>系统：
	            <select id="system-select" name="system" data-options="multiple:true">
			<option value="">&nbsp;</option>
                    </select>
                <a href="#" onclick="clearCombo('system-select')">清空</a>
            </td>
            <td>设备标识：	            
                    <select id="devID-select" name="devID" data-options="multiple:true">
                            <option value="">&nbsp;</option>
                    </select>
                <a href="#" onclick="clearCombo('devID-select')">清空</a>
            </td>  
            <td align="center"><a href="#" id="search-clear" class="easyui-linkbutton" iconCls="icon-search">清空</a></td>  
            </tr>  
            <tr>  
            <td>中文名称：<input class="easyui-textbox " type="text" name="devName"></input></td>  
            <td></td>
            <td>更新时间：<input   style="width:100px" id="from" name="from">-
			<input  style="width:100px" id="to" name="to"></td>  
            <td></td>
            </tr>  
            <tr>  
            <td></td>
            <td></td>
            <td></td>
            <td align="center"><a href="#" id="search-submit" class="easyui-linkbutton" iconCls="icon-search">查询</a></td>
            </tr>
        </table>  
    </form>  

</div>
<div  region="center">

<div id="import_excel">
<form id="import_excel_form" method="post"  enctype="multipart/form-data" style="padding:10px 20px 10px 40px;">
                <div style="margin-bottom:20px">
                        <input type="hidden" name="file_name" id="file_name">
			<div>选择文件:</div>
			<input class="easyui-filebox" id="excel_file" name="excel_file" data-options="required:'true',prompt:'选择需要上传的文件...',buttonText:'选择文件',accept:'application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'" style="width:100%">
		</div>
		<div>
			<a id="uploadExcel" class="easyui-linkbutton" style="width:100%">上传</a>
		</div>
</form>
</div>
<div id="dl-datagrid"></div>
</div>

<script type="text/javascript">
$(function(){
	$('#dl-datagrid').datagrid({
		title:'设备列表',
		//表单默认排序字段
		sortName:'deviceName',
		sortOrder:'asc',

        pagination:true,
        border:false,
        pageSize:50,  
        pageNumber:1,
        singleSelect:false,
        url: '${basePath}dl/getDeviceList',  
        loadMsg:'加载中...',  
        fitColumns: false, 
        fit: false, 

        columns: [[  
                   { field: 'id', checkbox: true},  
                   //{ field: 'tid', title: '编号', width:60 },  
                   { field: 'devIndex', title: '设备编号', width:150},
                   { field: 'lineID', title: '线路标识', width:60},
                   { field: 'stationID', title: '车站标识', width:60},
                   { field: 'sysID', title: '系统标识', width:60},
                   { field: 'devID', title: '设备标识', width:90},
                   { field: 'devArea', title: '设备安装分区', width:80},
                   { field: 'devNO', title: '设备数量号', width:80},
                   { field: 'devName', title: '设备中文名称', width:90},
                   { field: 'devAddress', title: '设备安装地点', width:90},
                   { field: 'sbdm', title: '图纸设备代码', width:90},
                   { field: 'lockOption', title: '连锁对象', width:60},
                   { field: 'boxID', title: '模块箱号', width:60},
                   { field: 'moduleTake', title: '所占端子排数', width:90},
                   { field: 'deviceSequence', title: '设备地址序列', width:90},
                   { field: 'beizhu1', title: '备注1', width:50},
                   { field: 'beizhu2', title: '备注2', width:50},
                   { field: 'beizhu3', title: '备注3', width:50},
                   { field: 'driverType', title: '驱动类型', width:70}
               ]],toolbar: [{  
                   text:'上传EXCEL',  
                   iconCls:'icon-add',  
                   handler:function(){  
                	   importExcel();  
                   }  
               },'-',{  
                   text:'下载模板',  
                   iconCls:'icon-edit',  
                   handler:function(){  
                       downLoadModel();  
                   }  
               },'-',{  
                   text:'导出所选记录',  
                   iconCls:'icon-sum',  
                   handler:function(){  
                       exportExcel();  
                   }  
               },'-',{  
                   text:'导出全部查询记录',  
                   iconCls:'icon-sum',  
                   handler:function(){  
                       exportExcelByParams();  
                   }  
               },'-',{  
                   text:'导出为FEP记录',  
                   iconCls:'icon-sum',  
                   handler:function(){  
                       exportFEPExcelByParams();  
                   }  
               }],
                onLoadSuccess:function(){
        	$('#dl-datagrid').datagrid('clearSelections');
        	
        },onClickRow: function (rowIndex, rowData) {
            $(this).datagrid('unselectRow', rowIndex);
        }
        });
	
	function importExcel()
	{
		$('#import_excel_form').form('clear');
		$("#import_excel").dialog('open');
	}
        
	function uploadExcel()
	{
		$('#import_excel_form').form('submit',{
			url: '${basePath}excel/uploadDpList', 
	        onSubmit: function () {        //表单提交前的回调函数 
            console.log('upload dplist');
                  var fileName = $('#excel_file').filebox('getText');
                  $('#file_name').attr('value',fileName);
	          return  $(this).form('validate'); // 如果验证不通过，返回false终止表单提交 
	        }, 
	        success: function (data){
	        	var jsonObj = eval("("+data+")");
	        	if ("success" == jsonObj.type) {
	            $.messager.show({ 
	              title: '提示消息', 
	              msg: jsonObj.message, 
	              showType: 'show', 
	              timeout: 1000, 
	              style: { 
	                right: '', 
	                bottom: '' 
	              } 
	            }); 
	            $('#dl-datagrid').datagrid('reload');  // 重新载入当前页面数据  
	            $('#import_excel').dialog('close'); //关闭窗口 
	          }else if("warning"== jsonObj.type){
	        	  $.messager.alert('提示信息', jsonObj.message, 'warning'); 
	          } 
	          else { 
	            $.messager.alert('提示信息', jsonObj.message, 'error'); 
	        }
	        }
		})
	}
        
                function downLoadModel()
                {
                    window.location.href='${basePath}file/device_list_model.xlsx';
                }
        		
		function updaterRow()
                {
                    var rows = $('#dl-datagrid').datagrid('getSelections');
                    if(rows.length == 0)
                    {  
                        $.messager.alert('提示',"请选择需要修改的记录",'warning');  
                        return;  
                    }  
                    if(rows.length > 1)
                    {  
                        $.messager.alert('提示',"只能选择一项记录进行修改",'warning');  
                        return;  
                    } 
                    $("#add_goods").form('load', rows[0]);
                    targetUrl = "${basePath}goods/updateGoods";
                    $("#add_goods").dialog('open');
		}
                
                function deleteRow()
                {

                }
        
        function exportExcel()
        {
            
            console.log('export deviceList');
            var rows = $('#dl-datagrid').datagrid('getSelections');
            var ids="";
            if(rows.length == 0)
            {  
                ids="";  
            }  
            if(rows.length > 1)
            {  
                $(rows).each(function()
                {
                    if(ids == "")
                    {
                            ids = this.lid;
                    }else{
                            ids += ","+this.lid;
                    }
		})
                ids ="("+ids+")";;  
            } 
            var url='${basePath}excel/downloadDpList';
            window.location.href=url+'?ids='+ids;
            
        }
        
        function exportExcelByParams()
        {
            var params = $('#dl-datagrid').datagrid('options').queryParams;
            var query = "?";
            $.each(params,function(key,value){
                    query = query + key + "=" + value + "&";
            })
            query = query.substring(0,query.length-1);
            var url='${basePath}excel/downloadDpList';
            window.location.href=url+query;
        }
        
        function exportFEPExcelByParams()
        {
            var params = $('#dl-datagrid').datagrid('options').queryParams;
            var query = "?";
            $.each(params,function(key,value){
                    query = query + key + "=" + value + "&";
            })
            query = query.substring(0,query.length-1);
            var url='${basePath}excel/downloadFEPDpList';
            window.location.href=url+query;
        }

	$("#import_excel").dialog({
	    title: '导入EXCEL',
	    width: 400,
	    height:200,
	    closed: true,
	    cache: false,
	    modal: true
	});
	
	$("#uploadExcel").on('click',function(){
		uploadExcel();
	});
});
</script>
<script type="text/javascript">
$(function()
{
    //复杂查询表单代码
		$("#from").datebox({
			editable:false,
			formatter:function(date){
				var years=date.getFullYear();//获取年
				var months=date.getMonth()+1;//获取日
				var dates=date.getDate();//获取月
				if(months<10){//当月份不满10的时候前面补0，例如09
					months='0'+months;
				}
				if(dates<10){//当日期不满10的时候前面补0，例如09
					dates='0'+dates;
				}
				
				return years+"-"+months+"-"+dates+" 00:00:00";
			}
		});
		
		$("#to").datebox({
			editable:false,
			formatter:function(date){
				var years=date.getFullYear();//获取年
				var months=date.getMonth()+1;//获取日
				var dates=date.getDate();//获取月
				if(months<10){//当月份不满10的时候前面补0，例如09
					months='0'+months;
				}
				if(dates<10){//当日期不满10的时候前面补0，例如09
					dates='0'+dates;
				}
				
				return years+"-"+months+"-"+dates+" 23:59:59";
			}
		});
		
		$("#search-clear").on('click',function(){
			$("#searchForm").form('clear');
		});
                
                $("#search-submit").on('click',function(){
                    console.log("test-search");
			var params = new Object();
			var fields = $('#searchForm').serializeArray(); //自动序列化表单元素为JSON对象 
                        var target = new Map();
			$.each(fields,function(i,field){
				//params[field.name]=field.value;
                                if(field.value == '' || field.value == null)
                                {
                                    return true;
                                }
                                if(!target.has(field.name))
                                {
                                    target.set(field.name,field.value);
                                }else
                                {
                                    var original = target.get(field.name);
                                    target.set(field.name,original+","+field.value);
                                }
			});
                        target.forEach(function (value, key, map) {
                            //alert(value);
                            params[key]=value; 
                        });
			$('#dl-datagrid').datagrid('options').queryParams = params;
			$('#dl-datagrid').datagrid('reload');
		});
                
     //填充下拉框
    fillEasyuiComboBox('${basePath}dl/getDeviceListStationID','station-select');
    fillEasyuiComboBox('${basePath}dl/getDeviceListSystemID','system-select');
    fillEasyuiComboBox('${basePath}dl/getDeviceListDevID','devID-select');
}
);
function clearCombo(dom)
{
    $("#"+dom).combobox('clear');
    $("#"+dom).combobox('setValue','');
}
        
</script>
</body>
</html>